<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/logic/factory/CommandFactory.php';
		require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php';
		
	$debug = FirePHP :: getInstance(true);
	$debug -> setEnabled(true);
	
	//Permite eliminar los notices
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];
	
	class PresenterCreateBranch {
		
		public function __construct() {}
		
		public function clickCreateBranch ($branch) {
			
			$address = explode(", ", $branch['address']);
			$country = $address[3];
			$stateProvince = $address[2];
			$city = $address[1];
			$zone = $address[0];
			
				    $GLOBALS['debug'] -> log($country, "pais---presentador branch");
					$GLOBALS['debug'] -> log($stateProvince, "provincia");
					$GLOBALS['debug'] -> log($city, "ciudad");
					$GLOBALS['debug'] -> log($zone, "zone");
					
			
				$command = CommandFactory :: createCommandCreateBranch ($branch['pk_rif'],$branch['name'],$country, $stateProvince, $city, $zone,date("Y-m-d", time()), '');
			
			$command -> execute();		
			return $command->getResult();
		
		}	
		
				/**
		 * Method to execute to select Branches
		 */
		public function selectBranches() {
			$command = CommandFactory :: createCommandSelectBranches();
			$command -> execute();
			$branches = $command -> getResult();
			$GLOBALS['debug']->log(' INICIO Funcion que llama al presentador para listar las sucursales');
				
			$result = '<table class="formTable" cellspacing="0" cellpadding="5">';
			$result .= '<tr class="odd">';
			$result .= '<td align="center"><b>Nombre</b></td>';
			$result .= '<td align="center"><b>Rif</b></td>';
			$result .= '<td align="center"><b>Direccion</b></td>';

			$result .= '</tr>';
			$i = 0; $unread = 0;
			while ($i < count($branches['pk_rif'])) {
				if ($i % 2 == 0) $result .= '<tr class="even">';
				else $result .= '<tr class="odd">';
				
				$result .= '<td align="center">' . $branches['name'][$i] . '</td>';
				$result .= '<td align="center">' . $branches['pk_rif'][$i] . '</td>';
				$result .= '<td align="center">' . $branches['address'][$i++] . '</td>';

			

				$result .= '</tr>';
			}
			
			
				$GLOBALS['debug']->log(' FIN Funcion  PRESENTADOR sucursales');
			return $result;
		}
		
		
		
		
	}
?>